<%--
  Created by IntelliJ IDEA.
  User: Master
  Date: 06.05.2011
  Time: 13:59:25
  To change this template use File | Settings | File Templates.
--%>
<%--
  Created by IntelliJ IDEA.
  User: Master
  Date: 06.05.2011
  Time: 9:34:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.transcargo.users.User" %>
<%@ include file="header.jsf"%>
<%@ include file="session.jsf"%>
<%
    if (User_Id <= 0) {
        response.sendRedirect("auth.jsp");
        return;
    }
    int Id = 0;
    String id = request.getParameter("recipient");
    if (id != null && id.length() > 0) Id = Integer.parseInt(id);
    String reply = request.getParameter("reply");
    String subject="";
    String body = "";
    if (reply != null && Integer.parseInt(reply) > 0) {
    	int mid = Integer.parseInt(reply);
    	list = dbase.execute("SELECT mail.sender_id, mail.subject, mail_body.body FROM mail, mail_body WHERE mail.id=mail_body.id AND mail.id=" + mid);
    	iter = list.iterator();
    	if (iter.hasNext()) {
    		String[] res = iter.next();
    		Id = Integer.parseInt(res[0]);
    		subject = res[1];
    		body = res[2];
    		if (!subject.substring(0,3).equals("RE: ")) subject = "RE: " + subject;
    		body = body.replaceAll("\n","\n> ");
    		body = "\n\n> " + body;
    	}
    	
    }
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  	<head><title>TransCargo</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="ajaxrequest.js"></script>
    <script type="text/javascript" src="forms.js"></script>
	<link type="text/css" href="transcargo.css" rel="stylesheet"/>
  </head>
  <body>
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr><td colspan="2">
			<%@include file="page_header.jsf"%>
        </td></tr>
        <tr><td width="80%" align="center">
            <b>Новое сообщение</b><br><br><br>
            <div id="ErrorPlaceHolder" class="errorString"></div>
            <form action="AddMailAction" method="POST" target="ifPost" name="mailform">
            <table cellpadding="4" cellspacing="1" bgcolor="#000000">
                <tr bgcolor="#FFFFFF"><td>Кому:</td><td><input name="to" size="58" disabled="true"><input type="hidden" name="recipient"><a href="company.jsp">Поиск</a> </td></tr>
                <tr bgcolor="#FFFFFF"><td>Приоритет:</td><td><select name="priority"><option value="0">Несрочный</option><option value="1" selected="">Нормальный</option><option value="2">Важный</option></select></td></tr>
                <tr bgcolor="#FFFFFF"><td>Тема:</td><td><input name="subject" size="66" value="<%=subject %>"></td></tr>
                <tr bgcolor="#FFFFFF"><td>Сообщение:</td><td><textarea name="text" cols="50" rows="6"><%=body %></textarea></td></tr>
                <tr bgcolor="#FFFFFF"><td colspan="2"><input type="submit" value="Отправить"></td></tr>
            </table><br><br>
            </form>
        </td><td valign="top"><%@include file="login.jsf"%><br><%@include file="quicksearch.jsf"%></td></tr>
        </table>
    <iframe name="ifPost" id="ifPost" width="0" height="0" style="visibility: hidden;width: 0;height: 0;" onload="handlePost(this);" onload="handlePost(this);"></iframe>
<%
    if (Id > 0) {
%>
    <script type="text/javascript">
        SendRequest('getuser?uid=' + <%=Id%> + '&short=on', ProcessRecipient);
    </script>
<%
    }
%>
  </body>
</html>
</html>